package com.leetcode.p100;

import com.bean.TreeNode;
import com.utils.TreeUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 采用 深度优先遍历(从根节点出发，先遍历右，再遍历左，直到把所有节点遍历完)
 */
public class Test199_2 {

    public List<Integer> rightSideView(TreeNode root) {
        List<Integer> res = new ArrayList<>();

        if (null == root) {
            return res;
        }

        help(res, root, 0);

        return res;
    }

    private void help(List<Integer> res, TreeNode root, int depth) {
        if (root == null) {
            return;
        }

        if (res.size() <= depth) {
            res.add(root.val);
        }

        depth++;
        help(res, root.right, depth);
        help(res, root.left, depth);
    }

    public static void main(String[] args) {
        TreeNode root = TreeUtils.buildTree();
        TreeUtils.showTree(root);

        Test199_2 test = new Test199_2();
        List result = test.rightSideView(root);
        System.out.println(result);
    }

}
